package com.example.book.sys.post.controller;

import com.example.book.base.BaseController;
import com.example.book.base.Result;
import com.example.book.domain.sys.SysPost;
import com.example.book.sys.post.service.SysPostService;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门机构控制器
 * @author haocj
 */
@RestController
@RequestMapping(value = "/sys/sysPost")
public class SysPostController extends BaseController {

    @Autowired
    private SysPostService sysPostService;

    @ModelAttribute
    public SysPost get(@RequestParam(required = false) String id) {
        if (StringUtils.isNotBlank(id)) {
            return sysPostService.get(id);
        } else {
            return new SysPost();
        }
    }

    @RequestMapping(value = "/info")
    public PageInfo<SysPost> list(SysPost sysPost){
        return sysPostService.findPage(sysPost);
    }


    @RequestMapping(value = "/findList")
    public List<SysPost> findList(SysPost sysPost){
        return sysPostService.findList(sysPost);
    }


    @RequestMapping(value = "/getById")
    public SysPost getById(SysPost sysPost){
        SysPost post = sysPostService.get(sysPost);
        return post;
    }

    /**
     * 新增 修改
     * @param sysPost
     * @return
     */
    @RequestMapping(value = "/save")
    public Result save(SysPost sysPost) {
        sysPostService.save(sysPost);
        return Result.success("保存成功");
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public Result delete(@RequestParam("ids") String[] ids){
        sysPostService.delete(ids);
        return Result.success();
    }

}
